package com.xncoding.jwt.config;

import com.xncoding.jwt.commons.SocketConstants;
import com.xncoding.jwt.handler.SocketHandler;
import com.xncoding.jwt.interceptor.WebSocketInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * <p>
 * 此类用于将webSocket相关会话请求注册到服务配置中
 * </p>
 *
 * @author feilong
 * @version 1.0
 * @since 2024/5/27
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Autowired
    private WebSocketInterceptor webSocketInterceptor;


    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {

        /***
         * <p>
         *     此处用于注册待办中心业务模块socket会话业务处理,如需新增请增加registry处理器
         * </p>
         *
         * @param registry socket注册处理器
         */
        registry.addHandler(new SocketHandler(), SocketConstants.MESSAGE_SERVICE_URL)
                .addInterceptors(webSocketInterceptor)
                .setAllowedOrigins("*");
    }
}
